<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: PortalErrorHandler.php 467 2011-01-25 17:24:30Z steen.rabol $
 * @package Pradoportal.Common
 *
 */

Prado::using('System.Util.TVarDumper');
Prado::using('System.Exceptions.TErrorHandler');
Prado::using('Application.Common.PortalException');

/**
 *
 * @package Pradoportal.Common
 */
class PortalErrorHandler extends TErrorHandler
{
	/**
	 * Displays error to the client user.
	 * THttpException and errors happened when the application is in <b>Debug</b>
	 * mode will be displayed to the client user.
	 * @param integer response status code
	 * @param Exception exception instance
	 */
	protected function handleExternalError($statusCode,$exception)
	{
		PortalUtil::Log('Erro: see below.');
		PortalUtil::Log($exception);

		// Try to show a nice error messages
		if($this->Service instanceof PortalPageService)
		{
			$message	= urldecode($this->getApplication()->getSecurityManager()->hashData($exception->getMessage()));

			// Prevent a endless loop
			if ($this->Service->RequestedPagePath != "System.ErrorReport")
			{
				$this->Response->redirect($this->Service->constructUrl('System.ErrorReport',array('msg'=> $message)));
			}
			else
			{
				parent::handleExternalError($statusCode, $exception);
			}
		}
		else
		{
			// Something is wrong.... Show normal PRADO error
			parent::handleExternalError($statusCode, $exception);
		}
	}
}

?>